// 搜索字符串拼接
export function param(json: any) {
    if (!json) return ''
    const list: string[] = []
    Object.keys(json).map((key) => {
        if (json[key] === undefined) return ''
        list.push(encodeURIComponent(key) + '=' + encodeURIComponent(json[key]))
    })
    return list.join('&')
}

// 搜索字符串解拼
export function getQueryObject(url: string) {
    url = url == null ? window.location.href : url
    const search = url.substring(url.lastIndexOf('?') + 1)
    const obj = {}
    const reg = /([^?&=]+)=([^?&=]*)/g
    search.replace(reg, (rs, $1, $2) => {
        const name = decodeURIComponent($1)
        let val = decodeURIComponent($2)
        val = String(val)
        obj[name] = val
        return rs
    })
    return obj
}
